package cn.kgc.itrip.auth.service;

import cn.kgc.itrip.beans.pojo.ItripUser;

public interface TokenService {
    String TOKEN_KEY_PREFIX = "token:";
    // 过期时间：单位(S)
    int TOKEN_TIME_OUT = 7200;
    // Token在剩余1800s之后 可以置换
    int TOKEN_REFRESH_TIME = 1800;
    // 缓存老Token
    int TOKEN_CACHE_OLD_TIME = 120;

    /**
     * 删除Token
     * @param token
     * @throws Exception
     */
    void delToken(String token)throws Exception;

    /**
     * 置换Token
     * @param token
     * @param userAgent
     * @param currentUser
     * @return
     * @throws Exception
     */
    String refreshToken(String token, String userAgent, ItripUser currentUser)throws Exception;

    /**
     * 检查Token是否到达置换时间
     * @param token
     * @param userAgent
     * @return
     * @throws Exception
     */
    boolean checkTokenTimeOut(String token, String userAgent)throws Exception;

    /**
     * 保存Token
     * @param token
     * @param itripUser
     * @param userAgent
     * @throws Exception
     */
    void saveToken(String token, ItripUser itripUser, String userAgent)throws Exception;

    /**
     * 生成Token
     * @param itripUser
     * @param userAgent
     * @return
     * @throws Exception
     */
    String genToken(ItripUser itripUser, String userAgent)throws Exception;
}
